package foo;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Packet implements Serializable {
	final String message;

	public Packet(final String message) {
		this.message = message;
	}

	@Override
	public String toString() {
		return message;
	}

	public static void main(final String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
		final Packet p = new Packet("Msg");
		final ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream("packet.out"));
		o.writeObject(p);

		final ObjectInputStream i = new ObjectInputStream(new FileInputStream("packet.out"));
		final Packet p2 = (Packet) i.readObject();

		System.out.println(p);
		System.out.println(p2);
	}
}
